//
//  MAPopView.m
//  meiang_edu
//
//  Created by hfcb on 2018/8/5.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MAPopView.h"
#import "MAPopViewCell.h"
#import "MABabyModel.h"
#import "MAStaffModel.h"

@interface MAPopView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation MAPopView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.autoresizingMask = UIViewAutoresizingNone;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
    }
    return self;
}
+ (instancetype)popView {
    MAPopView *popView = [[MAPopView alloc] init];
    
    popView.width = IS_IPHONE_5 ?SCREEN_WIDTH * 0.59 : SCREEN_WIDTH * 0.49;
    if (IS_IPHONE_5) {
        popView.height = SCREEN_HEIGHT * 0.53;
    } else if (IS_IPHONE_X) {
        popView.height = SCREEN_HEIGHT * 0.35;
    } else {
        popView.height = SCREEN_HEIGHT * 0.43;
    }
    
    popView.myTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    popView.myTableView.tableFooterView = [UIView new];
    popView.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    return popView;
}

#pragma mark - UITableViewDelegate, UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.models.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = indexPath.row;
    MAPopViewCell *popcell = [MAPopViewCell cellWithTableView:tableView];
    MAStaffModel *model = self.models[row];
    popcell.nameLabel.text = [NSString stringWithFormat:@"切换为 %@",model.cname];
    
    return popcell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DLog(@"");
    MAStaffModel *model = self.models[indexPath.row];
    if (self.selectedBlock) {
        self.selectedBlock(model);
    }
}

@end
